package com.hiro.framework.tilegame.controller;

import java.awt.event.KeyEvent;

import com.egghiro.framework.j2se.game.core.key.SKeyCodeMapper;
import com.hiro.framework.tilegame.controller.system.STileGameSystem;
import com.hiro.framework.tilegame.model.actor.ITileBoard;


public class WaitingForKeyState extends GameState {
    private static WaitingForKeyState instance;
    private static byte[] lock = new byte[0];
    private SKeyCodeMapper keyCodeMapper = new SKeyCodeMapper();

//    private FifteenPuzzleCanvas canvas;
//    private ItileBoard tileBoard;

//    private WaitingForKeyState(FifteenPuzzleCanvas canvas, ItileBoard tileBoard) {
//        this.canvas = canvas;
//        this.tileBoard = tileBoard;
//    }
    
    private WaitingForKeyState(ITileBoard tileBoard) {
        super(tileBoard);
    }

    public static WaitingForKeyState getInstance(ITileBoard tileBoard) {
        if (instance == null || instance.equals(tileBoard) == false) {
            synchronized (lock) {
                if (instance == null || instance.equals(tileBoard) == false) {
                    instance = new WaitingForKeyState(tileBoard);
                }
            }
        }
        return instance;
    }

    @Override
    public void keyPressed(KeyEvent e) {
//        // TODO DEBUG-START
//        if (e.isControlDown()) {
//            canvas.setState(GameClearState.getInstance(canvas, tileBoard));
//            GameClearState.getInstance(canvas, tileBoard).showClearDialog();
//            return;
//        }
//        // TODO DEBUG-END
        AnimationState animationState = AnimationState.getInstance(tileBoard);
        STileGameSystem.getInstance().setState(animationState);
        animationState.start(keyCodeMapper.getGameKeyCode(e.getKeyCode()));
    }
}
